package com.hkts.management.expressage.controller;

import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import com.hkts.management.expressage.QueryTrack;
import com.hkts.management.expressage.core.IBaseClient;
import com.hkts.management.expressage.request.QueryTrackParam;
import com.hkts.management.expressage.request.QueryTrackReq;
import com.hkts.management.expressage.utils.PropertiesReader;
import com.hkts.management.expressage.utils.SignUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/order/expressage")
@Api(tags = "物流管理接口")
public class ExpreController {

    private String key = PropertiesReader.get("key");
    private String customer = PropertiesReader.get("customer");
    @RequestMapping(value = "/getQueryTrack",method = RequestMethod.GET)
    @ApiOperation(value = "查询快递")
    public Map<String,Object> QueryTrack(String com,String num) throws Exception{

        QueryTrackReq queryTrackReq = new QueryTrackReq();
        QueryTrackParam queryTrackParam = new QueryTrackParam();
        queryTrackParam.setCom(com);
        queryTrackParam.setNum(num);
        queryTrackParam.setResultv2("1");
        String param = new Gson().toJson(queryTrackParam);
        queryTrackReq.setParam(param);
        queryTrackReq.setCustomer(customer);
        queryTrackReq.setSign(SignUtils.querySign(param ,key,customer));
        IBaseClient baseClient = new QueryTrack();
        String body = baseClient.execute(queryTrackReq).getBody();

        Map<String,Object> map = new Gson().fromJson(body, new TypeToken<HashMap<String,Object>>(){}.getType());
        return map;
    }
}
